import sqlite3

#/Users/webusi/deploy/spider/sqlite.db

class SqlLite:
    def __init__(self, path=None):
        if path == None:
            self.path = 'unkown'
        else:
            self.path = path

    def set_path(self, path):
        self.path = path

    def executeOne(self, sql, tupple=None):
        if self.path == 'unkown':
            return

        conn = sqlite3.connect(self.path)
        cursor = conn.cursor()
        if tupple!=None:
            cursor.execute(sql, tupple)
        else:
            cursor.execute(sql)

        conn.commit()
        cursor.close()
        conn.close()

    def executeMulti(self, sql, tupples):
        if self.path == 'unkown':
            return

        conn = sqlite3.connect(self.path)
        cursor = conn.cursor()
        cursor.executemany(sql, tupples)
        conn.commit()
        cursor.close()
        conn.close()

    def select(self, sql):
        if self.path == 'unkown':
            return

        conn = sqlite3.connect(self.path)
        cursor = conn.cursor()
        cursor.execute(sql)
        rows = cursor.fetchall()
        cursor.close()
        conn.close()
        return rows

sqlite = SqlLite()
